<?php

namespace app\model\exam;

use app\model\BaseModel;
use app\model\office\OfficeClass;
use app\model\office\OfficeMajor;
use app\model\office\OfficeUser;
use think\model\concern\SoftDelete;

class ExamRecord extends BaseModel
{

    use SoftDelete;

    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 模型名称
     * @var string
     */
    protected $table = 'free_exam_record';
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = '0000-00-00 00:00:00';
    protected $type = [
        'status' => 'boolean',
    ];

    public function searchIdcardAttr($query, $value)
    {
        if (isset($value))  $query->where('idcard', 'like', '%' . $value . '%');
    }

    public function searchUserNameAttr($query, $value)
    {
        if (isset($value))  $query->where('user_name', 'like', '%' . $value . '%');
    }

    public function searchSubmitTypeAttr($query, $value)
    {
        if (isset($value)) $query->where('submit_type', 'like', '%' . $value . '%');
    }

    public function searchExamTypeAttr($query, $value)
    {
        if (isset($value)) $query->where('exam_type', 'like', '%' . $value . '%');
    }

    public function searchReadStatusAttr($query, $value)
    {
        if (isset($value)) $query->where('read_status', 'like', '%' . $value . '%');
    }

    public function searchExamIdAttr($query, $value)
    {
        if (isset($value)) $query->where('exam_id', 'like', '%' . $value . '%');
    }

    public function getExamTypeAttr($value)
    {
        $status = [1 => '考试', 0 => '作业'];
        return $status[$value];
    }

    public function getReadStatusAttr($value)
    {
        $status = [1 => '已批阅', 0 => '未批阅'];
        return $status[$value];
    }

    public function getSubmitTypeAttr($value)
    {
        $status = [1 => '正常提交', 0 => '暂时保存'];
        return $status[$value];
    }

    public function setSubmitTypeAttr($value)
    {
        $status = ['正常提交' => 1, '暂时保存' => 0];
        return $status[$value];
    }

    public function setExamTypeAttr($value)
    {
        $status = ['考试' => 1, '作业' => 0];
        return $status[$value];
    }

    public function setReadStatusAttr($value)
    {
        $status = ['已批阅' => 1, '未批阅' => 0];
        return $status[$value];
    }

    public function OfficeClass()
    {
        return $this->hasOne(OfficeClass::class, 'id', 'class_id');
    }

    public function exam()
    {
        return $this->hasOne(ExamSend::class, 'id', 'exam_id');
    }

    public function majors()
    {
        return $this->hasOne(OfficeMajor::class, 'id', 'major_id');
    }

}